package test7;

import com.tyfspring.beans.factory.DefaultListableBeanFactory;
import com.tyfspring.beans.support.XmlBeanDefinitionReader;
import org.junit.Test;

/**
 * @Description TODO
 * @Author shallow
 * @Date 2023/4/10 19:46
 */
public class test {
    @Test
    public void test(){
        //初始化beanFactory
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        //加载配置文件
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        reader.loadBeanDefinitions("classpath:spring.xml");
        //BeanFactory后处理器
        //实例化之前修改bean信息
        MyBeanFactoryPostProcessor beanFactoryPostProcessor = new MyBeanFactoryPostProcessor();
        beanFactoryPostProcessor.postProcessBeanFactory(beanFactory);
        //实例化后bean后处理器修改bean属性信息
        MyBeanPostProcessor beanPostProcessor = new MyBeanPostProcessor();
        beanFactory.addBeanPostProcessor(beanPostProcessor);
        //获取bean对象
        UserService userService = beanFactory.getBean("userService", UserService.class);
        String result = userService.queryUserInfo();
        System.out.println("结果是"+result);
    }
}
